import requests
import json, cv2
from base64 import b64decode
import numpy as np
import logging

def result_post():
    url = "http://8.134.53.114:8277/visual/uavAiAlarm/msgUpload"
    json_data = {}
    """南水直播检测报警测试"""
    logging.info("|INFO: post data to {}|".format(url))
    ret = requests.post(url=url,json=json_data)
    status_code = ret.status_code
    if status_code != 200:
        logging.error("|ERR: code {}, result_post fail|".format(status_code))

def post_powerLine():
    json_data = {
        "id":0,
        "images":[
                # "http://36.138.254.186:888/ftp/ftp_test/0000008_02999_d_0000042.jpg", 
                # "http://36.138.254.186:888/ftp/vehicle/press_lane.jpg",
                "http://36.138.254.186:888/ftp/ftp_test/DJI_20230817145233_0104_Z.JPG",
                "http://36.138.254.186:888/ftp/ftp_test/9999951_00000_d_0000303.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/DJI_20230817145233_0104_Z.JPG",
                # "http://36.138.254.186:888/ftp/ftp_test/DJI_20230817145233_0104_Z.JPG",
                # "http://36.138.254.186:888/ftp/ftp_test/crack/DJI_20230217123043_0002_W.JPG",
                # "http://36.138.254.186:888/ftp/ftp_test/crack/img_20230220_112918.077.jpg",
                ],

        # "show_score":1,
    }
    url = "http://0.0.0.0:2682/powerLine_detect"

    request = requests.post(url=url,json = json_data)
    with open("data/output/temp_file.json","w") as f:
        jsondata = json.loads(request.text)
        json.dump(jsondata,f,ensure_ascii=False,indent=4)

    print(request)

def post_test():
    json_data = {
        "id":0,
        "images":[
                # # # fire_detect
                # "http://183.237.169.245:888/ftp/DJI_20240822081832_0003_V.jpg",
                # 误检图片(湖面云层倒影误检)
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/烟雾/DJI_20240827152245_0005_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/DJI_20240827152318_0008_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/DJI_20240827152257_0006_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/烟雾/DJI_20240827152318_0008_V.jpg",
                # # landslide_detect
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/landslide/DJI_20231026155242_0024_W.JPG",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/landslide/DJI_20230223150921_0003_W_1800.JPG",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/landslide/DJI_20230223150921_0003_W_1500.JPG",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/landslide/DJI_20230223150921_0003_W_1200.JPG",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/landslide/DJI_20230223150921_0003_W_900.JPG",
                # # vehicle_detect
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/2/DJI_20240827104918_0004_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/vehicle/DJI_20240822144057_0012_V.jpg",
                # # # # # people_detect
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/people/9999951_00000_d_0000003.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/people/0000031_00000_d_0000037.jpg",
                # # # # ecological_damage
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/ecological_damage/DJI_20231107152044_0122_W.JPG",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/ecological_damage/DJI_20231107152024_0115_W.JPG",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/ecological_damage/DJI_20231107151632_0039_W.JPG",
                # # # forest_pest_detect 
                # # 正样本
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/forest_pest/2/DJI_20240815084626_0001_W.MP4_20240815_090629.201.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/forest_pest/2/DJI_20240815084626_0001_W.MP4_20240815_090624.649.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/landship/forest_pest/2/DJI_20240815084626_0001_W.MP4_20240815_090450.457.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/漏检/9.9/DJI_20240909091702_0004_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/漏检/9.9/DJI_20240909092022_0009_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/漏检/9.9/DJI_20240909092132_0011_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/漏检/9.9/DJI_20240909092340_0015_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/漏检/9.9/DJI_20240905144838_0007_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/漏检/9.9/DJI_20240905144919_0008_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/漏检/9.9/DJI_20240909092132_0011_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/漏检/9.9/DJI_20240909092340_0015_V.jpg",
                #  误检图片(夜间广角误检)
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/烟雾/DJI_20240827214146_0009_V.jpg",
                #   路面误检(蓝色车辆)
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/误检/903/DJI_20240903151908_0012_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/误检/903/DJI_20240903151947_0014_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/误检/903/DJI_20240903151957_0015_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/误检/903/DJI_20240903144952_0006_V.jpg",
                # #   蓝色屋顶
                "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/误检/903/DJI_20240903152217_0024_V.jpg",
                "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/误检/903/DJI_20240903152226_0025_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/误检/903/DJI_20240903151811_0007_V.jpg",
                # "http://36.138.254.186:888/ftp/ftp_test/smoke/烟火数据图/误检/903/DJI_20240903151715_0002_V.jpg",
                ],
        # "show_score":1,
    }
    url = "http://0.0.0.0:8011/all_detect"
    # url = "http://0.0.0.0:8011/fire_detect"
    # url = "http://0.0.0.0:8011/landslide_detect"
    # url = "http://0.0.0.0:8011/vehicle_detect"
    # url = "http://0.0.0.0:8011/people_detect"
    # url = "http://0.0.0.0:8011/ecological_damage_detect"
    # url = "http://0.0.0.0:8011/forest_pest_detect"

    request = requests.post(url=url,json = json_data)
    with open("data/output/temp_file.json","w") as f:
        jsondata = json.loads(request.text)
        json.dump(jsondata,f,ensure_ascii=False,indent=4)

    print(request)

"http://8.134.53.114:888/ftp/building_change/train_a.png"

def post_test_building_change():
    json_data = {
        "id":0,
        "images":[
                ["http://8.134.53.114:888/ftp/building_change/train_a.png","http://8.134.53.114:888/ftp/building_change/train_b.png",]
                ],
    }
    url = "http://0.0.0.0:2682/building_change"

    request = requests.post(url=url,json = json_data)
    with open("data/output/temp_file.json","w") as f:
        jsondata = json.loads(request.text)
        json.dump(jsondata,f)

    print(request)

def rtsp_post():
    json_data = {
    "rtmp_push_path":"rtmp://218.94.155.86:1936/live/livestream_86_2",
    # "rtmp_push_path":"rtmp://218.94.155.86:1936/live/livestream_8_69439858747240f292120e6af0b6a28d",
    "rtsp_origin":"rtmp://218.94.155.86:1936/live/livestream_86_1",
    }
    # json_data = {
    #         "clientip":"192.168.1.22",
    #         "format": "json",
    #         "data":None,
    #         "results": None,
    #         "classify_ms":0,
    #         "wait_in_queue_ms":0
    #     }

    url = "http://0.0.0.0:8011/deepstream_rtsp_detect"

    request = requests.post(url=url,json = json_data)
    print(request)

def stop_rtmp():
    json_data = {'rtmp_push_path': "rtmp://218.94.155.86:1936/live/livestream_86_2"}
    url = "http://0.0.0.0:8011/stop_deepstream_rtsp_detect"

    request = requests.post(url=url,json = json_data)
    print(request)

def video_test():
    json_data = {
        "id":0,
    # "save_path":"/home/smartgis/workspace/project/smart_server/data/output/RTMP",
        # "video_path": "/home/smartgis/workspace/project/smart_server/data/input/DJI_20240912084643_0001_S.mp4",
        # "video_path":["http://36.138.254.186:888/ftp/ftp_test/RTMP/DJI_20240912084643_0001_S.mp4"]
        #  "video_path":["http://36.138.254.186:888/ftp/ftp_test/RTMP/DJI_20240918082111_0002_T.mp4"]
        "video_path":["http://36.138.254.186:888/ftp/ftp_test/RTMP/DJI_20240815084626_0002_S.MP4"],
        # "video_path":["http://183.237.169.245:888/ftp/vis_DJI_20240912084643_0001_S.mp4"]
    }

    url = "http://0.0.0.0:8011/video_detect"

    request = requests.post(url=url,json = json_data)
    print(request)
if __name__ == "__main__":
    # post_powerLine()
    video_test()
    # post_test()
    # post_test_building_change()
    # result_post()
    # rtsp_post()
    # stop_rtmp()
